package com.cy.web;

import com.alibaba.fastjson.JSONArray;
import com.cy.Redis.CacheRedisService;
import com.cy.bean.Question1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import redis.clients.jedis.Jedis;

import java.util.List;

@Controller
public class Question1Controller {
    @Autowired
    private CacheRedisService cacheRedisService;
    Jedis jedis = new Jedis("43.143.77.47",6379);

    @RequestMapping("getQuestion1")
    @ResponseBody
    public List<String> getQuestion1(){
//        Jedis jedis = new Jedis("43.143.77.47",6379);
        List<String> lrange = jedis.lrange("1",0,2);
        return lrange;
    }
    @RequestMapping("/demoHash")
    @ResponseBody
    public void demoHash(){
        jedis.hset("user","123456","1");
    }
    @RequestMapping("/getQue")
    @ResponseBody
    public String getQue(){
        /*获取redis中对应用户对应的取题范围*/
        int res = Integer.parseInt(jedis.hget("user","123456"));
        /*获取取题范围的上一题和下一题*/
        List<String> list = jedis.lrange("question1List",res-1,res+1);
        String questionList = JSONArray.toJSONString(list);
        return questionList;
    }
}
